﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Othello_Game
{
    /// <summary>
    /// A class used to calculate the game score (whis is currently leading, who won, etc'...)
    /// </summary>
    public class Score
    {
        /// <summary>
        /// The number of positions the black player owns
        /// </summary>
        public int BlackPlayer { get; private set; }
        /// <summary>
        /// The number of positions the white player owns
        /// </summary>
        public int WhitePlayer { get; private set; }

        /// <summary>
        /// Initializes a new instance of the Othello_Game.Score class
        /// </summary>
        /// <param name="blackPlayer1"></param>
        /// <param name="whitePlayer2"></param>
        public Score(int blackPlayer1, int whitePlayer2)
        {
            this.BlackPlayer = blackPlayer1;
            this.WhitePlayer = whitePlayer2;
        }

        /// <summary>
        /// Check who is leading
        /// </summary>
        /// <returns></returns>
        public players WhoIsLeading()
        {
            if (BlackPlayer > WhitePlayer)
            {
                return players.PLAYER1;
            }
            else if (WhitePlayer > BlackPlayer)
            {
                return players.PLAYER2;
            }
            else
            {
                return players.NONE;
            }
        }

        /// <summary>
        /// Check if one of the players conquered the board.
        /// </summary>
        /// <returns>True if one of the players has no buttons on the board</returns>
        public bool DidSomeOneConquer()
        {
            return ((this.BlackPlayer == 0) || (this.WhitePlayer == 0));
        }

        /// <summary>
        /// Check if the game is over and there are no more free spaces to conquer.
        /// </summary>
        /// <returns>True if the game is over. False otherwise.</returns>
        public bool IsGameOver()
        {
            // Count the total number of pieces on board
            return ((BlackPlayer + WhitePlayer) == GeneralConsts.Instance.TotalBoardPlaces);
        }
    }
}
